﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using VSA.Entity;

namespace VSA.BLL
{
    public class FunctionsBLL
    {
        private static readonly VSA.DAL.FunctionsDAL dal = new VSA.DAL.FunctionsDAL();
        public FunctionsBLL()
        { }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int Did)
        {
            return dal.Exists(Did);
        }

        public static bool Contains(string value)
        {
            return dal.Exists(value);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static bool Add(VSA.Entity.Functions model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static bool Update(VSA.Entity.Functions model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static bool Delete(int Did)
        {

            return dal.Delete(Did);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string Didlist)
        {
            return false;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static VSA.Entity.Functions GetModel(int Did)
        {
            return dal.GetModel(Did);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public VSA.Entity.Activity GetModelByCache(int Did)
        {

            string CacheKey = "t_FunctionModel-" + Did;
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(Did);
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (VSA.Entity.Activity)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static List<VSA.Entity.Functions> GetModelList(string strWhere)
        {
            return dal.GetListArray(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<VSA.Entity.Functions> DataTableToList(DataTable dt)
        {
            List<VSA.Entity.Functions> modelList = new List<VSA.Entity.Functions>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                VSA.Entity.Functions model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new VSA.Entity.Functions();
                    if (dt.Rows[n]["Did"].ToString() != "")
                    {
                        model.Did = int.Parse(dt.Rows[n]["Did"].ToString());
                    }
                    model.FunctionName = dt.Rows[n]["FunctionName"].ToString();
                    if (dt.Rows[n]["CreateDate"].ToString() != "")
                    {
                        model.CreateDate = DateTime.Parse(dt.Rows[n]["CreateDate"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetAllList()
        {
            return GetList("");
        }
    }
}